<?php 
if (!defined('e107_INIT')) { exit; }
require_once(e_HANDLER.'shortcode_handler.php');
global $tp;
$invoice_shortcodes = $tp->e_sc->parse_scbatch(__FILE__);

/*

SC_BEGIN SHOP_NAME_AND_LOGO
    global $shop_settings;
    $text = "<table cellpadding='0' cellspacing='0' border='0'><tr>";
    if (file_exists(e_PLUGIN."e107shop/images/logo.png")) $text .= "<td><img src='".e_PLUGIN."e107shop/images/logo.png' alt='' /></td>";
    else $text .= "<td><img src='".e_PLUGIN."e107shop/images/logo_.png' alt='' /></td>";
    $text .= "<td style='vertical-align: middle; font-size: 20pt; font-weight: bold;'>".$shop_settings['store_name']."</td>";
    $text .= "</tr></table>";
    return $text;
SC_END

SC_BEGIN SHOP_ADDRESS
    global $shop_settings;
    switch ($parm) {
        case 1:
            return $shop_settings['store_address1'];
            break;
        case 2:
            return $shop_settings['store_address2'];
            break;
        case 3:
            return $shop_settings['store_address3'];
            break;
        case 4:
            return $shop_settings['store_address4'];
            break;
    }
SC_END

SC_BEGIN ORDER_NUMBER
    $order = getcachedvars('orderinfo');
    return lan_invoice_title." ".$order['number'];
SC_END

SC_BEGIN ORDER_DATE
    $order = getcachedvars('orderinfo');
    return $order['date'];
SC_END

SC_BEGIN OFFLINE_PAYMENT
    global $shop_settings;
    $order = getcachedvars('orderinfo');
    if ($order['paymentmethod'] == lan_gateway_offline) {
        $text = "<div style='border: 1px solid #828282; margin-right: 50px; padding: 10px;'>";
        $text .= $shop_settings['invoice_offline_line1'];
        $text .= "<br />";
        $text .= $shop_settings['invoice_offline_line2'];
        $text .= "<br />";
        $text .= $shop_settings['invoice_offline_line3'];
        $text .= "<br />";
        $text .= $shop_settings['invoice_offline_line4'];
        $text .= "<br />";
        $text .= $shop_settings['invoice_offline_line5'];
        $text .= "<br />";
        $text .= $shop_settings['invoice_offline_line6'];
        $text .= "</div>";
    }
    return $text;
SC_END

SC_BEGIN CUSTOMER_DATA
    $order = getcachedvars('orderinfo');
    return "<div style='padding: 10px 10px 10px 20px;'>".$order['customerinfo']."</div>";
SC_END

SC_BEGIN VAT_NUMBER
    global $shop_settings;
    if (empty($shop_settings['license'])) return;
    else return lan_invoice_tax_heading." ".$shop_settings['license'];
SC_END

SC_BEGIN PAYMENT_METHOD
    $order = getcachedvars('orderinfo');
    return "<b>".lan_payment_method."</b> ".$order['paymentmethod'];
SC_END

SC_BEGIN PRICE_DETAILS
    global $shop_settings;
    $order = getcachedvars('orderinfo');
    $text = "<div style='padding: 10px 30px 10px 20px;'>";
    $text .= "<table width='100%'>";
    $text .= "<tr><th style='text-align: left;'>".lan_price."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($order['product_price'])."</td></tr>";
    if ($order['coupon_amount'] != 0) {
        $text .= "<tr><th style='text-align: left;'>".lan_global_discount."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8")."-".e107shop_get_numformat($order['coupon_amount'])."</td></tr>";
        $midtotal = $order['product_price'] - $order['coupon_amount'];
        $text .= "<tr><th style='text-align: left;'>".lan_global_subtotal."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($midtotal)."</td></tr>";
    }
    $text .= "<tr><th style='text-align: left;'>".lan_invoice_ph."</th>";
    if($shop_settings["postage_method"] == 2 || $shop_settings["postage_method"] == "3")
        $text .= "<td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($order['postage_price'])."</td></tr>";
    else $text = "<td style='text-align: right;'>".lan_global_postage_included."</td></tr>";
    $text .= "<tr><th style='text-align: left;'>".lan_global_subtotal."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($order['subtotal'])."</td></tr>";
    $text .= "<tr><th style='text-align: left;'>".lan_invoice_tax."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($order['tax'])."</td></tr>";
    if(trim($order['extrapaymentinfo']) == "") {
        $text .= "<tr><th style='text-align: left;'>".lan_invoice_total."</th>";
        $extraCost = roundfix($order['extracost'], 2);
        $grandTotal = roundfix(floatval($order['total']) + $extraCost, 2);
    } else $text .= "<tr><th style='text-align: left;'>".lan_global_subtotal."</th>";
    $text .= "<td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($order['total'])."</td></tr>";
    if(trim($order['extrapaymentinfo']) != "") {
        $text .= "<tr><th style='text-align: left;'>".constant("lan_gateway_".$order['gateway'])." Cost (" . $order['extrapaymentinfo'] .")</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").e107shop_get_numformat($extraCost)."</td></tr>";
        $text .= "<tr><th style='text-align: left;'>".lan_invoice_total."</th><td style='text-align: right;'>".html_entity_decode($shop_settings["currency_symbol"], ENT_COMPAT, "UTF-8").$grandTotal."</td></tr>";
    }
    $text .= "</tr></table>";
    $text .= "</div>";
    return $text;
SC_END

SC_BEGIN INVOICE_DATA
    $orderlines = getcachedvars('orderlines');
    $text = "<div style='height: 600px; border: 1px solid #828282;'>";
    $text .= "<table width='100%' style='border-collapse: collapse;'>";
    $text .= "
    <tr valign='top'>
        <th style='border: 1px solid #828282; background-color: #C0C0C0; padding: 0px 10px 0px 10px;'>
            ".lan_invoice_ref."
        </th>
        <th style='border: 1px solid #828282; background-color: #C0C0C0; padding: 0px 10px 0px 10px; text-align: left;'>
            ".lan_global_product_name."
        </th>
        <th style='border: 1px solid #828282; background-color: #C0C0C0; padding: 0px 10px 0px 10px;'>
            ".lan_global_quantity."
        </th>
        <th style='border: 1px solid #828282; background-color: #C0C0C0; padding: 0px 10px 0px 10px; text-align: right;'>
            ".lan_global_price_per_item."
        </th>
        <th style='border: 1px solid #828282; background-color: #C0C0C0; padding: 0px 10px 0px 10px; text-align: right;'>
            ".lan_global_total_price."
        </th>
    </tr>
    ";
    foreach ($orderlines as $orderarray) {
        $text .= "<tr valign='top'>";
        $counter = 0;
        foreach ($orderarray as $value) {
            switch ($counter) {
                case 0:
                case 2:
                    $text .= "<td style='text-align: center; border: 1px solid #828282; padding: 5px 10px 5px 10px; vertical-align: middle;'>";
                    break;
                case 3:
                case 4:
                    $text .= "<td style='text-align: right; border: 1px solid #828282; padding: 5px 10px 5px 10px; vertical-align: middle;'>";
                    break;
                default:
                    $text .= "<td style='text-align: left; border: 1px solid #828282; padding: 5px 10px 5px 10px;'>";
            }
            $text .= $value."</td>";
            $counter++;
        }
        $text .= "</tr>";
    }
    $text .= "</table>";
    $text .= "</div>";
    return $text;
SC_END

*/
